package animals;

import genetics.DiploidAttribute;
import attributes.*;

public class Cow extends Animal {

	/**
	 * number of chromosomes in a cow (chromosomes are not yet fully
	 * implemented)
	 */
	public static final int nChromosomes = 29;

	/**
	 * number of attributes (diploid attributes)
	 */
	public static final int nAttributes = 2;

	/*
	 * indices for specific attributes
	 */
	public static final int fleck = 0;
	public static final int color = 1;

	/**
	 * constructor creates a new empty cow
	 */
	public Cow() {
		atts = new DiploidAttribute[nAttributes];
	}

	/**
	 * creates a new random cow (with random attributes)
	 * 
	 * @param seed
	 *            not yet implemented (so basically just useless)
	 */
	public Cow(long seed) {
		this();

		Fleck fleck1 = new Fleck();
		atts[fleck] = new DiploidAttribute(fleck1, fleck1);

		Color color1 = new Color();
		atts[color] = new DiploidAttribute(color1, color1);
	}
	
	@Override
	public Animal mate(Animal b) {
		if (!(b instanceof Cow)) {
			throw new InvalidCrossBreedingException(
					"Cows cannot mate with other animals.");
		}
		Cow partner = (Cow) b;
		Cow calf = new Cow();
		calf.sex = Math.random() > 0.495 ? Sex.MALE : Sex.FEMALE;

		for (int i = 0; i < nAttributes; i++) {
			calf.atts[i] = new DiploidAttribute(atts[i].haploidize(),
					partner.atts[i].haploidize());
		}

		return calf;
	}

	@Override
	public String toString() {
		return "FleckSize: " + ((Fleck) atts[fleck].getPhenotype()).fleckSize
				+ ", " + atts[fleck].getPhenotype().dominantRecessive;
	}

	@Override
	public int getNChromosomes() {
		return nChromosomes;
	}
}
